package com.godfan.domain;


import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import java.io.IOException;
import java.util.List;

public class MybatisTest {

    @Test
    public void finAll() throws IOException {
        SqlSession sqlSession= MybatisUtils.getsqlSession();
        List<Student> student = sqlSession.selectList("StudentMapper.selectAll");
        for (Student student1 : student) {
            System.out.println(student1);
        }
       MybatisUtils.closs(sqlSession);
    }
    @Test
    public void fin() throws IOException {
        SqlSession sqlSession= MybatisUtils.getsqlSession();
        Object o = sqlSession.selectOne("StudentMapper.select",1);
        System.out.println(o);
        MybatisUtils.closs(sqlSession);
    }
    @Test
    public void insert()throws IOException{
        SqlSession sqlSession= MybatisUtils.getsqlSession(true);
        int zzz = sqlSession.insert("StudentMapper.insert", new Student(null, "zzz", 18, "2000-10-10"));
        System.out.println(zzz);
        MybatisUtils.closs(sqlSession);
    }
    @Test
    public void update()throws IOException{
        SqlSession sqlSession= MybatisUtils.getsqlSession(true);
        int zzz = sqlSession.insert("StudentMapper.update",new Student(2, "王五", 25, "1996-06-06"));
        System.out.println(zzz);
        MybatisUtils.closs(sqlSession);
    }
    @Test
    public void delete() throws IOException{
        SqlSession sqlSession= MybatisUtils.getsqlSession(true);
        int delete = sqlSession.delete("StudentMapper.delete",2);
        System.out.println(delete);
    }
}
